<template>
  <header id="header_top">
      <slot name="logo"></slot>
      <slot name="search"></slot>
      <section class="head_goback" v-if="goBack" @click="$router.go(-1)">
        <svg width="100%" height="100%" xmlns="http://www.w3.org/2000/svg" version="1.1">
            <polyline points="12,18 4,9 12,0" style="fill:none;stroke:rgb(255,255,255);stroke-width:2"/>
        </svg>
      </section>
      <router-link :to="isLogin?'/profile':'/login'" class="head_login" v-if="$route.name === 'home' || $route.name === 'msite' || $route.name === 'confirmOrder'">
        <svg class="user_avatar" v-if="isLogin">
            <use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#user"></use>
        </svg>
        <span class="login_span" v-else>登录|注册</span>
      </router-link>
      <section class="title_head ellipsis" v-if="headTitle">
        <span class="title_text">{{headTitle}}</span>
      </section>
      <slot name="changecity"></slot>
      <slot name="msite-title"></slot>
  </header>
</template>

<script>
import {mapState,mapActions} from 'vuex'
export default {
  props:['headTitle','goBack'],
  computed:{
    ...mapState(['user']),
    isLogin(){
      if(this.user && this.user.user_id){
        return true;
      }
      return false;
    }
  },
  created(){
      // if(!this.user || !this.user.user_id){
      //     let user = getUser();
      //     if(user){
      //       this.setUserInfo(user);
      //     }
      // }
  },
  methods:{
    ...mapActions(['setUserInfo'])
  }
}
</script>

<style lang="scss" scoped>
@import '~@styl/mixin.scss';
#header_top{
    background: $blue;
    position: fixed;
    z-index: 100;
    top:0;
    left: 0;
    @include wh(100%,1.95rem);
    .head_login{
      right: .55rem;
      @include sc(0.65rem,#fff);
      @include ct;
      .login_span{
        color: #fff;
      }
      .user_avatar{
        @include wh(0.8rem,0.8rem);
        fill: #fff;
      }
    }
    .title_head{
      color: #fff;
      @include center;
      width: 50%;
      text-align: center;
      .title_text{
        color: #fff;
        @include sc(0.8rem,#fff);
        font-weight: bold;
      }
      

    }
    .head_goback{
      @include ct;
      left:0.4rem;
      @include wh(0.6rem,1rem)
    }
}
</style>